<?php

use Robbo\Presenter\PresentableInterface;

class Place extends Eloquent implements PresentableInterface
{
    /**
     * Get the post's Category.
     *
     * @return User
     */
    public function category()
    {
        return $this->belongsTo('Category', 'category_id');
    }

    /**
     * Get the post's locations.
     *
     * @return array
     */
    public function locations()
    {
        return $this->hasMany('Location');
    }
    /**
     * Get the place's provincePlaces.
     *
     * @return array
     */
    public function provincePlaces()
    {
        return $this->hasMany('ProvincePlaces');
    }


    /**
     * Deletes a place.
     *
     * @return bool
     */
    public function delete()
    {
        // Delete the blog post
        return parent::delete();
    }

    /**
     * Returns a formatted place entry,
     * this ensures that line breaks are returned.
     *
     * @return string
     */
    public function description()
    {
        return nl2br($this->description);
    }

    public function getPresenter()
    {
        return new PlacePresenter($this);
    }

    /**
     * Get the date the place was created.
     *
     * @param  \Carbon|null $date
     * @return string
     */
    public function date($date=null)
    {
        if (is_null($date)) {
            $date = $this->created_at;
        }

        return String::date($date);
    }

    /**
     * Returns the date of the place creation,
     * on a good and more readable format :)
     *
     * @return string
     */
    public function created_at()
    {
        return $this->date($this->created_at);
    }

    /**
     * Returns the date of the place last update,
     * on a good and more readable format :)
     *
     * @return string
     */
    public function updated_at()
    {
        return $this->date($this->updated_at);
    }

    public static function getBanksByProvince($province_id)
    {
        return self::where('province_id', $province_id)->get();
    }

}
